﻿using FastCodeGeneration.Core.Framework;
using FastCodeGeneration.Entity;
using FastCodeGeneration.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FastCodeGeneration.Repository
{
    public class TableColumnRepository : BaseRepository<TableColumn>, ITableColumnRepository
    {
        public List<TableColumn> GetColumnsByProjectId(int projectId)
        {
            return Context.Queryable<TableColumn>().Where(e => e.ProjectId == projectId).ToList();
        }

        public Dictionary<string, List<TableColumn>> GetByTableNames(int projectId, List<string> tableNames)
        {

            Dictionary<string, List<TableColumn>> keyValuePairs = new Dictionary<string, List<TableColumn>>();
            var list = dataBase.Queryable<TableColumn>().Where(e => e.ProjectId == projectId && tableNames.Contains(e.TableName)).ToList();
            foreach (var item in list)
            {
                if (!keyValuePairs.ContainsKey(item.TableName))
                {
                    keyValuePairs.Add(item.TableName, new List<TableColumn>());
                }
                if (!"create_by,last_modified_by,create_time,last_modified_time".Contains(item.Name))
                {
                    keyValuePairs[item.TableName].Add(item);
                }
            }
            return keyValuePairs;
        }



    }
}
